const path = require("path");

const {
    CleanWebpackPlugin
} = require("clean-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const webpack = require('webpack');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const VueLoaderPlugin = require('vue-loader/lib/plugin')


module.exports = {
    mode: "development",
    entry: "./src/main.js",
    output: {
        path: path.resolve(__dirname, "dist"),
        filename: "js/bundle.[hash].js"
    },
    plugins: [
        new CleanWebpackPlugin({
            path: "./dist"
        }),
        new HtmlWebpackPlugin({
            template: "./src/index.html"
        }),
        new webpack.BannerPlugin("made in lnboxue time:" + Date.now()),
        new MiniCssExtractPlugin({
            filename: "css/main.css"
        }),
        new VueLoaderPlugin()
    ],
    module: {
        rules: [{
                test: /\.js$/,
                use: {
                    loader: "babel-loader",
                    options: {
                        presets: [
                            "@babel/preset-env"
                        ],
                        plugins: [
                            "@babel/plugin-transform-runtime"
                        ]

                    }
                },
                exclude: /node_modules/
            },
            {
                test: /\.css$/,
                use: [
                    process.env.NODE_ENV !== 'production' ?
                    'vue-style-loader' :
                    MiniCssExtractPlugin.loader,
                    'css-loader',
                    'postcss-loader'
                ]
            },
            {
                test: /\.less/,
                use: [
                    process.env.NODE_ENV !== 'production' ?
                    'vue-style-loader' :
                    MiniCssExtractPlugin.loader,
                    'vue-style-loader',
                    'css-loader',
                    'postcss-loader',
                    "less-loader"
                ]

            },
            {
                test: /\.scss/,
                use: [
                    process.env.NODE_ENV !== 'production' ?
                    'vue-style-loader' :
                    MiniCssExtractPlugin.loader,
                    'vue-style-loader',
                    'css-loader',
                    'postcss-loader',
                    "sass-loader"
                ]

            },
            {
                test: /\.(jpg|png|jpeg|gif)$/,
                use: {
                    loader: "url-loader",
                    options: {
                        limit: 30 * 1024,
                        outputPath: "images"
                    }
                }
            },
            {
                test: /\.(eot|woff|woff2|ttf)/,
                use: "url-loader"
            },
            {
                test: /\.vue$/,
                use: "vue-loader"
            }
        ]
    },
    devServer: {
        port: 3000,
        contentBase: "./dist",
        host: "127.0.0.1",
        hot: true,
        open: true
    }
}